<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="result">
<div class="div_header1">Messages</div>
<table cellspacing="0" id="mytable" width="100%" style="float: left;">
<thead>
<tr style="background:HoneyDew; height: 32px;">
<th align="left">Date</th>
<th width="100" align="left">Sender</th>
<th width="100" align="left">Recipient</th>
</tr>
</thead>
<tbody>
 <?php if(!empty ($allmsgs)){
 foreach($allmsgs as $allmsg):    
     ?>

<tr>
<td>
    <?php echo date('d-m-Y',  strtotime($allmsg['Message']['created'])); ?>
</td>
<td>
    <?php echo $allmsg['Sender']['username']; ?>
</td>
<td>
    <?php echo $allmsg['Recipient']['username']; ?>
</td>
</tr>
<tr>
<td colspan="3" style="border-bottom: 6px dotted gold;text-align:left">
  <b><?php echo $allmsg['Sender']['username']; ?> wrote:</b> <?php echo $allmsg['Message']['message'];?>
</td>

</tr>
    <?php 
       endforeach;
    }else{?>
<tr>
<td colspan="3" style="border-bottom: 6px dotted gold;">
   No Message Found.
</td>
</tr>
        <?php } ?>
</tbody></table>
<?php
if($flag!=null){
?>
    <form accept-charset="utf-8" action="<?php echo Configure::read('base_url');?>messages/product_message" method="post" id="productmessage">
<table cellspacing="0" >
             <tbody>
                 <tr>
                    <td style="color: #73AE0B; font-size: 15px;" >Write New Message</td>
                  </tr>
                <tr>
                    <td ><span style="padding-right:50px;">From: &nbsp;&nbsp;&nbsp;<b>
                    <?php echo $session->read('Auth.User.username');?></b></span><span style="padding-right:50px;">To: &nbsp;&nbsp;&nbsp;
                    <?php echo $productinfo['User']['username'];?></span>
                    </td>
                </tr>
                 <tr>
                    <td >Subject: About approval of your "<?php echo $productinfo['Product']['products_title'];?>",(Item #<?php echo $productinfo['Product']['id'];?>)</td>
                  </tr>
                  <tr>
                    <td ></td>
                  </tr>
                   <tr>
                    <td >
                    <?php
                echo $this->Form->hidden('Message.item',array('value'=>$productinfo['Product']['id']));
		echo $this->Form->hidden('Message.subject',array('value'=>"About approval of your ".'"'.$productinfo['Product']['products_title'].'"'.", (Item # ".$productinfo['Product']['id'].")"));
		echo $this->Form->hidden('MessageTrack.to_id',array('value'=>$productinfo['User']['id']));
		echo $this->Form->input('Message.message',array('cols'=>60,'class'=>'required'));
                ?>
                    </td>
                  </tr>
                 <tr>
                    <td >
                    <input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="button" id="button" value="Submit" />
                    </td>
                  </tr>
                    <tbody>
                </table>
</form>
<?php
}
?>
</div>
</body>
</html>
<?php  echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js")); ?>
<script type="text/javascript">
 jQuery(document).ready(function(){

// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="<?php echo Configure::read('base_url');?>img/loading.gif" alt="loading..." /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});

		var v = jQuery("#productmessage").validate({
                    rules: {
                    },
      submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});


                 });


 </script>